import Fly from 'flyio/dist/npm/wx'
import toast from './toast.js'
import store from '@/store'

const fly = new Fly()
fly.config.baseURL = 'https://slwl-api.itheima.net'

// 请求拦截器
fly.interceptors.request.use(config => {
	const token = store.getters.token
	if(token) {
		config.headers.Authorization = token
	}
	return config
})

// 响应拦截器
fly.interceptors.response.use(response => {
	return response.data
}, err => {
	toast.err(err.message)
	return Promise.reject(err)
})

export default fly